package com.tutu.service.impl;

import com.tutu.core.Constant;
import com.tutu.core.api.LogInfoApiUrls;
import com.tutu.service.LogInfoService;
import com.tutu.utils.HttpRequestUtil;
import com.tutu.utils.PathUtils;
import com.tutu.utils.UnicodeUtil;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * LogInfoServiceImpl
 * Created by 涂奕恒 on 2023/8/17 10:03.
 */
@Service
public class LogInfoServiceImpl implements LogInfoService {

    @Override
    public Map<String, Object> pageByParams(String keyWord, Integer pageNum, Integer pageSize) {
        return HttpRequestUtil.getOnlyData(LogInfoApiUrls.base_prefix + LogInfoApiUrls.page, "keyWord=" + UnicodeUtil.unicodeEncode(keyWord) + "&pageNum=" + pageNum + "&pageSize=" + pageSize);
    }

    public static void saveLogInfo(HttpServletRequest request, String content) {
        String ip = PathUtils.getRemoteAddr(request);
        String masterId = request.getSession().getAttribute(Constant.CURRENT_LOGIN_MASTER_ID) + "";
        String masterName = request.getSession().getAttribute(Constant.CURRENT_LOGIN_MASTER_NAME) + "";

        if (!ip.equals("0:0:0:0:0:0:0:1")) HttpRequestUtil.getCompleteData(LogInfoApiUrls.base_prefix + LogInfoApiUrls.create, "ip=" + ip + "&content=" + UnicodeUtil.unicodeEncode("ID：" + masterId + "，账号：" + masterName + "：" + content));
    }
}